package com.infore.dataAudit.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.springframework.stereotype.Service;

import com.infore.dataAudit.service.TasksService;



/**
 * 任务相关服务层实现类
 * @author cys
 *
 */
@Service("tasksService")
public class TasksServiceImpl implements TasksService {
    
    @Resource
    private TaskService taskService;
    @Resource
    private RuntimeService runtimeService;
    
    
    
    
    @Override
    public void finishTask(Task task, String comment, Map<String, Object> param, 
            Integer reviewPass) {
        //默认3通过
        reviewPass = reviewPass == null ? 3: reviewPass;
        runtimeService.setVariable(task.getExecutionId(), "reviewPass", reviewPass);
        if (comment != null) {
            taskService.addComment(task.getId(), task.getProcessInstanceId(), comment);
        }
        taskService.complete(task.getId(), param);
    }

    @Override
    public List<Task> queryTask(String instanceId, String assignee, String appCode) {
        if("tongzpt_app".equals(appCode)) {
            return taskService.createTaskQuery().processInstanceId(instanceId).taskAssignee(assignee).list();
        }else {
            return taskService.createTaskQuery().processInstanceId(instanceId).list();
        }
    }
    
    

}
